//
//  SDHSportsMatchLiveCell.m
//  SDHSportsNews
//
//  Created by MichaelShan on 2021/3/13.
//

#import "SDHSportsMatchLiveCell.h"
#import "SDHSportsMatchLiveModel.h"

@interface SDHSportsMatchLiveCell ()

@property (nonatomic, strong) UILabel *timeLb;
@property (nonatomic, strong) UIView *contentBgView;
@property (nonatomic, strong) UILabel *contentLb;

@end

@implementation SDHSportsMatchLiveCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = UIColorFromRGB(48, 48, 48);
        [self initUI];
    }
    
    return self;
}

- (void)initUI {
    UILabel *timeLb = [UILabel new];
    timeLb.textAlignment = NSTextAlignmentCenter;
    timeLb.textColor = [UIColor whiteColor];
    timeLb.backgroundColor = UIColorFromRGB(182, 182, 182);
    timeLb.clipsToBounds = YES;
    timeLb.layer.cornerRadius = 11;
    timeLb.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:timeLb];
    self.timeLb = timeLb;
    timeLb.text = @" 20' ";
    [timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(10);
        make.height.mas_equalTo(22);
    }];
    
    UIView *contentBgView = [UIView new];
    contentBgView.backgroundColor = [UIColor whiteColor];
    contentBgView.clipsToBounds = YES;
    contentBgView.layer.cornerRadius = 8;
    [self.contentView addSubview:contentBgView];
    self.contentBgView = contentBgView;
    
    UILabel *contentLb = [UILabel new];
    contentLb.textColor = [UIColor grayColor];
    contentLb.font = [UIFont systemFontOfSize:15];
    contentLb.numberOfLines = 0;
    contentLb.textAlignment = NSTextAlignmentLeft;
//    contentLb.backgroundColor = [UIColor greenColor];
    [self.contentView addSubview:contentLb];
    self.contentLb = contentLb;
    contentLb.text = @"With the referee's whistle, the first half of the game began";
    [contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(timeLb).offset(10);
        make.top.mas_equalTo(timeLb.mas_bottom).offset(15);
        make.right.mas_equalTo(-25);
        make.bottom.mas_equalTo(-15);
    }];
    
    [contentBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(timeLb);
        make.top.mas_equalTo(timeLb.mas_bottom).offset(5);
        make.right.mas_equalTo(-15);
        make.bottom.mas_equalTo(-5);
    }];
}

- (void)updateContent:(id)obj {
    SDHSportsMatchLiveModel *model = (SDHSportsMatchLiveModel *)obj;
    self.timeLb.text = [NSString stringWithFormat:@" %@ ", model.time];
    if (model.time.length == 0) {
        [self.timeLb mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0);
        }];
    } else {
        [self.timeLb mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(22);
        }];
    }
    
    self.contentLb.text = model.enText;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
